package ModelLayer;
import java.util.ArrayList;
import ModelLayer.Loan;

/**
 * Write a description of class LoanContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class LoanContainer
{
    // instance variables - replace the example below with your own
    private ArrayList<Loan> loans;
    private static LoanContainer instance;
    int index = 0;

    public LoanContainer()
    {
        loans = new ArrayList<Loan>();
    }

    public static LoanContainer getInstance()
    {
        if(instance == null)
        {
            instance = new LoanContainer();
        }
        return instance;
    } 
    public void createLoan(Person loanPerson, DVD dvdTitle, Copy loanCopy,
                int borrowDay, int borrowMonth, int returnDay, int returnMonth)
    {        
      long id = loans.size() + 1;   
      System.out.println(id);
      Loan newLoan = new Loan(loanPerson, dvdTitle, loanCopy, id, borrowDay, borrowMonth, returnDay, returnMonth);
      loans.add(newLoan);
    }   
    
    public Loan findLoan(long searchLoanID)
    {   
        for(Loan loan : loans)
        {
            if (loan.getID() == searchLoanID)
            {
                return loan;
            }
        }
        
        return null;
    }
    
    public void deleteLoan(long searchLoanID)
    {
        for(int i = 0; i < loans.size(); i++)
        {
            if (loans.get(i).getID() == searchLoanID)
            {
                loans.remove(i);
            }
        }
    }
    
    public ArrayList listAllLoans()
    {   
        ArrayList<String> completeLoanList = new ArrayList<String>(); 
        for(Loan loan : loans)
            {
                completeLoanList.add(" Loan Person: " + loan.getLoanPerson());
                completeLoanList.add(" DVD title: " + loan.getDVDTitle());
                completeLoanList.add(" Borrow day: " + Integer.toString(loan.getBorrowDay()));
                completeLoanList.add(" Borrow Month: " + Integer.toString(loan.getBorrowMonth()));
                completeLoanList.add(" Return day: " + Integer.toString(loan.getReturnDay()));
                completeLoanList.add(" Return Month: " + Integer.toString(loan.getReturnMonth()));
            }
        return completeLoanList;
    }
}    
    

